HA$PBExportHeader$w_backup.srw
forward
global type w_backup from window
end type
type st_ruta from singlelineedit within w_backup
end type
type hpb_1 from hprogressbar within w_backup
end type
type rb_1 from radiobutton within w_backup
end type
type rb_2 from radiobutton within w_backup
end type
type st_2 from statictext within w_backup
end type
type cb_7 from commandbutton within w_backup
end type
type cb_6 from commandbutton within w_backup
end type
type sle_1 from singlelineedit within w_backup
end type
type dw_2 from datawindow within w_backup
end type
type gb_1 from groupbox within w_backup
end type
end forward

global type w_backup from window
integer width = 2249
integer height = 1216
boolean titlebar = true
string title = "DATA BASES"
boolean controlmenu = true
boolean minbox = true
long backcolor = 67108864
string icon = "AppIcon!"
boolean center = true
st_ruta st_ruta
hpb_1 hpb_1
rb_1 rb_1
rb_2 rb_2
st_2 st_2
cb_7 cb_7
cb_6 cb_6
sle_1 sle_1
dw_2 dw_2
gb_1 gb_1
end type
global w_backup w_backup

type variables
string is_database, kk
end variables

forward prototypes
public subroutine fw_salir ()
end prototypes

public subroutine fw_salir ();//


end subroutine

on w_backup.create
this.st_ruta=create st_ruta
this.hpb_1=create hpb_1
this.rb_1=create rb_1
this.rb_2=create rb_2
this.st_2=create st_2
this.cb_7=create cb_7
this.cb_6=create cb_6
this.sle_1=create sle_1
this.dw_2=create dw_2
this.gb_1=create gb_1
this.Control[]={this.st_ruta,&
this.hpb_1,&
this.rb_1,&
this.rb_2,&
this.st_2,&
this.cb_7,&
this.cb_6,&
this.sle_1,&
this.dw_2,&
this.gb_1}
end on

on w_backup.destroy
destroy(this.st_ruta)
destroy(this.hpb_1)
destroy(this.rb_1)
destroy(this.rb_2)
destroy(this.st_2)
destroy(this.cb_7)
destroy(this.cb_6)
destroy(this.sle_1)
destroy(this.dw_2)
destroy(this.gb_1)
end on

event open;// Autor:  Manuel Rojas M.
// E-mail: mrojas@mavila.com.pe
// Lima-Peru

IF Sqlca.SqlCode  = -1  or Sqlca.SqlCode = 100 or  Sqlca.SqlCode = 0 THEN 
	disconnect;
END IF
string ls_ruta
ls_ruta= gs_Unidad+"\RecursosApp.ini"


SQLCA.DBMS = "SNC SQL Native Client(OLE DB)"
SQLCA.LogPass		='sistemas'
SQLCA.LogId        ='sa'
SQLCA.ServerName	=	ProfileString(ls_ruta , "sqlca", "servername", "")
SQLCA.AutoCommit = False
SQLCA.DBParm = "Database='master',CommitOnDisconnect='No',Provider='SQLNCLI10',TrimSpaces=1,AppName='Recursos y Aplicaciones v1.0"
connect;

if sqlca.sqlcode <> 0 then
	//w_splash.SetPosition(NoTopmost!)
	MessageBox ("Sorry! Cannot Connect To Database", sqlca.sqlerrtext)
	w_sysmain.of_close_tab()
	return
end if



dw_2.settransobject(sqlca)
dw_2.retrieve()
sle_1.setfocus( )
end event

event closequery;close(this)
end event

type st_ruta from singlelineedit within w_backup
integer x = 55
integer y = 1012
integer width = 2135
integer height = 92
integer taborder = 40
integer textsize = -9
integer weight = 400
fontcharset fontcharset = ansi!
fontpitch fontpitch = variable!
fontfamily fontfamily = swiss!
string facename = "Arial"
long textcolor = 33554432
boolean displayonly = true
borderstyle borderstyle = stylelowered!
end type

type hpb_1 from hprogressbar within w_backup
boolean visible = false
integer x = 46
integer y = 640
integer width = 489
integer height = 148
unsignedinteger maxposition = 100
unsignedinteger position = 50
integer setstep = 10
end type

type rb_1 from radiobutton within w_backup
integer x = 87
integer y = 108
integer width = 334
integer height = 72
integer textsize = -10
integer weight = 400
fontcharset fontcharset = ansi!
fontpitch fontpitch = variable!
fontfamily fontfamily = swiss!
string facename = "Arial"
long textcolor = 33554432
long backcolor = 67108864
string text = "Backup"
end type

event clicked;int reg
if rb_1.checked=true then
	sle_1.enabled=true
	dw_2.enabled=true
	sle_1.setfocus()
	dw_2.retrieve()
	st_ruta.text=""
	reg=dw_2.getrow()
	if reg  > 0 then
		dw_2.selectrow(0,false)
		dw_2.selectrow(reg,true)
	end if
	parent.title='Backup DataBase'
end if
	
end event

type rb_2 from radiobutton within w_backup
integer x = 91
integer y = 188
integer width = 347
integer height = 72
integer textsize = -10
integer weight = 400
fontcharset fontcharset = ansi!
fontpitch fontpitch = variable!
fontfamily fontfamily = swiss!
string facename = "Arial"
long textcolor = 33554432
long backcolor = 67108864
string text = "Restore"
end type

event clicked;if rb_2.checked=true then
	sle_1.enabled=false
	dw_2.enabled=true
	cb_7.setfocus()
	dw_2.retrieve()
	st_ruta.text=""
	dw_2.selectrow(1,true)
	parent.title='Restore DataBase'
end if
	
end event

type st_2 from statictext within w_backup
integer x = 50
integer y = 924
integer width = 402
integer height = 64
integer textsize = -10
integer weight = 700
fontcharset fontcharset = ansi!
fontpitch fontpitch = variable!
fontfamily fontfamily = swiss!
string facename = "Arial"
long textcolor = 33554432
long backcolor = 67108864
string text = "RUTA:"
boolean focusrectangle = false
end type

type cb_7 from commandbutton within w_backup
event ue_backup ( )
event ue_restore ( )
integer x = 64
integer y = 352
integer width = 311
integer height = 92
integer taborder = 40
integer textsize = -10
integer weight = 700
fontcharset fontcharset = ansi!
fontpitch fontpitch = variable!
fontfamily fontfamily = swiss!
string facename = "Arial"
string text = "Ruta"
end type

event ue_backup();integer li_rpta
string ls_path,ls_filename,ls_filepath
ls_filename=sle_1.text

li_rpta=GetFileSaveName("Seleccione Directorio y Nombre de Backup",ls_filepath,ls_filename,"Bak","Files Bak(*.bak),*.bak")
if li_rpta=1 then
	st_ruta.text=ls_filepath 
else
	messagebox("Backup","Directorio o Nomnre no Valido")
	return
end if



end event

event ue_restore();integer li_rpta
string ls_path,ls_filename,ls_filepath
ls_filename=sle_1.text

li_rpta=GetFileOpenName ('Seleccione el archivo de copia de seguridad',ls_filepath,ls_filename,'BAK','Copias de Seguridad (*.bak),*.bak')
if li_rpta=1 then
	st_ruta.text=ls_filepath	
else
	messagebox("Backup","Directorio o Nomnre no Valido")
	return
end if
end event

event clicked;// rb_1 Backup
if rb_1.checked=true then
	triggerevent("ue_backup")
end if
// rb_2 Restore
if rb_2.checked=true then
	triggerevent("ue_restore")
end if


end event

type cb_6 from commandbutton within w_backup
event ue_restore ( )
event ue_backup ( )
integer x = 59
integer y = 472
integer width = 311
integer height = 92
integer taborder = 30
integer textsize = -10
integer weight = 700
fontcharset fontcharset = ansi!
fontpitch fontpitch = variable!
fontfamily fontfamily = swiss!
string facename = "Arial"
string text = "Generar"
end type

event ue_restore();string ls_rest, ruta,ls_db

ls_db=dw_2.object.databases[dw_2.getrow()]
ruta=st_ruta.text

if Messagebox('Restore','Esta seguro de contiuar',question!,yesno!,2)=2 then
	return
end if
if ls_db = 'MASTER' then
	Messagebox('Restore BD','LA BD : '+ls_db+' No se puede restaurar por este Medio',stopsign!)
	return
end if

ls_rest="RESTORE DATABASE " + ls_db + " FROM DISK = '" + ruta + "'"
execute immediate :ls_rest using sqlca;

IF Sqlca.SqlCode  = -1  then
 Messagebox('Error','Error en la DB: '+string(sqlca.sqlerrtext),exclamation!)	
else
	Messagebox('Restore BD','Restauraci$$HEX1$$f300$$ENDHEX$$n de BD: '+ls_db+' Satisfactoria')
end if
end event

event ue_backup();string ls_back, ruta,ls_db

ls_db=dw_2.object.databases[dw_2.getrow()]

ruta=st_ruta.text

ls_back="BACKUP database " + ls_db + " to disk = '" + ruta + "' with FORMAT"

execute immediate :ls_back using sqlca;

IF Sqlca.SqlCode  = -1  then
	Messagebox('Error','Error en la DB: '+string(sqlca.sqlerrtext),exclamation!)
else
	Messagebox('Backup','Backup de BD: '+ls_db+' Satisfactoria')
end if

end event

event clicked;string ls_query, ruta,ls_db
if isnull(st_ruta.text) or len(st_ruta.text) < 1 then
	messagebox('Error','Selecion un Directorio Valido o Nombre de Archivo *.Bak')
	return
end if

ls_db=dw_2.object.databases[dw_2.getrow()]
ruta=st_ruta.text

if rb_1.checked=true then
	ls_query="BACKUP database " + ls_db + " to disk = '" + ruta + "' with FORMAT"
	execute immediate :ls_query using sqlca;
end if
if rb_2.checked=true then
	if Messagebox('Restore','Esta seguro de contiuar',question!,yesno!,2)=2 then
		return
	end if
	if ls_db = 'MASTER' then
		Messagebox('Restore BD','LA BD : '+ls_db+' No se puede restaurar por este Medio',stopsign!)
		return
	end if
	ls_query="RESTORE DATABASE " + ls_db + " FROM DISK = '" + ruta + "'"
	execute immediate :ls_query using sqlca;
end if
IF Sqlca.SqlCode  = -1  then
 Messagebox('Error','Error en la DB: '+string(sqlca.sqlerrtext),exclamation!)	
else
	Messagebox(parent.title,'Proceso de BD: '+ls_db+' Satisfactoria')
end if

close(parent)
end event

type sle_1 from singlelineedit within w_backup
event ue_key pbm_enchange
integer x = 617
integer y = 64
integer width = 613
integer height = 100
integer taborder = 40
integer textsize = -10
integer weight = 400
fontcharset fontcharset = ansi!
fontpitch fontpitch = variable!
fontfamily fontfamily = swiss!
string facename = "Arial"
long textcolor = 33554432
boolean enabled = false
textcase textcase = upper!
borderstyle borderstyle = stylelowered!
end type

event ue_key;string ls_key,ls_find
long ll_find,ll_kk
int reg
//dw_2.SetFilter("Databases like '"+upper(sle_1.text)+"%"+"'")
//dw_2.Filter()
ls_find = upper(Trim(sle_1.Text))
ll_find = dw_2.Find("databases like '" + ls_find +"%"+ "'", 1, dw_2.rowcount())
if ll_find > 0 then
	dw_2.setrow(ll_find)
	dw_2.scrolltorow(ll_find)
//	dw_2.selectrow(0,false)
//	dw_2.selectrow(ll_find,true)
else
	dw_2.setrow(1)
	dw_2.scrolltorow(1)
//	dw_2.selectrow(0,false)
//	dw_2.selectrow(1,true)
end if


end event

type dw_2 from datawindow within w_backup
event ue_clikc pbm_dwnrowchange
event kkk pbm_dwnitemchangefocus
event ue_changed pbm_dwnrowchange
event ue_up pbm_keyup
integer x = 608
integer y = 184
integer width = 1189
integer height = 780
integer taborder = 20
boolean enabled = false
string title = "none"
string dataobject = "d_database"
boolean vscrollbar = true
borderstyle borderstyle = stylelowered!
end type

event ue_changed;int reg

reg=dw_2.getrow()

if reg  > 0 then
	dw_2.selectrow(0,false)
	dw_2.selectrow(reg,true)
	is_database=string(dw_2.getitemstring(reg,"databases"))
	
	if kk="ok" then
		sle_1.text=dw_2.getitemstring(reg,"Databases")
		kk="oo"
	end if
	//sle_1.text=dw_2.getitemstring(reg,"databases")
end if

end event

event clicked;////triggerevent(doubleclicked!)
////sle_1.text=""
//int reg
//string kk
//reg=dw_2.getrow()
//
//dw_2.selectrow(0,false)
//dw_2.selectrow(reg,true)
////is_database=string(dw_2.getitemstring(reg,"databases"))
////sle_1.text=dw_2.object.databases[reg]
//kk=dw_2.object.databases[reg]
//messagebox("MAN",kk)

kk="ok"
end event

type gb_1 from groupbox within w_backup
integer x = 69
integer y = 36
integer width = 494
integer height = 244
integer taborder = 10
integer textsize = -10
integer weight = 700
fontcharset fontcharset = ansi!
fontpitch fontpitch = variable!
fontfamily fontfamily = swiss!
string facename = "Arial"
long textcolor = 33554432
long backcolor = 67108864
string text = "Opciones"
end type

